<!DOCTYPE html>


<html lang="en">
  

    <head>
      <meta charset="utf-8" />
        
      <meta
        name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1"
      />
      <title>《JavaScript高级程序设计》- 第三章：语言基础 |  欢迎</title>
  <meta name="generator" content="hexo-theme-ayer">
      
      <link rel="shortcut icon" href="/favicon.ico" />
       
<link rel="stylesheet" href="/dist/main.css">

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css"
      />
      
<link rel="stylesheet" href="/css/custom.css">
 
      <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
       
 

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bulma@5.0.1/bulma.min.css"
      />
      <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.js"></script>

      <!-- mermaid -->
      
      <style>
        .swal2-styled.swal2-confirm {
          font-size: 1.6rem;
        }
      </style>
    <link rel="alternate" href="/atom.xml" title="欢迎" type="application/atom+xml">
</head>
  </html>
</html>


<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-JavaScript学习/《JavaScript高级程序设计》- 第三章：语言基础"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  《JavaScript高级程序设计》- 第三章：语言基础
</h1>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2022/02/11/JavaScript%E5%AD%A6%E4%B9%A0/%E3%80%8AJavaScript%E9%AB%98%E7%BA%A7%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E3%80%8B-%20%E7%AC%AC%E4%B8%89%E7%AB%A0%EF%BC%9A%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/" class="article-date">
  <time datetime="2022-02-11T02:27:20.000Z" itemprop="datePublished">2022-02-11</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/JavaScript%E5%AD%A6%E4%B9%A0/">JavaScript学习</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> Word count:</span>
            <span class="post-count">6.5k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> Reading time≈</span>
            <span class="post-count">26 min</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h3 id="第三章：语言基础"><a href="#第三章：语言基础" class="headerlink" title="第三章：语言基础"></a>第三章：语言基础</h3><h3 id="3-1-语法"><a href="#3-1-语法" class="headerlink" title="3.1 语法"></a>3.1 语法</h3><blockquote>
<p>ECMAScript语法很大程度上借鉴了C以及其他类C语言</p>
</blockquote>
<h4 id="3-1-1-区分大小写"><a href="#3-1-1-区分大小写" class="headerlink" title="3.1.1 区分大小写"></a>3.1.1 区分大小写</h4><blockquote>
<p>ECMAScript严格区分大小写</p>
</blockquote>
<h4 id="3-1-2-标识符"><a href="#3-1-2-标识符" class="headerlink" title="3.1.2 标识符"></a>3.1.2 标识符</h4><blockquote>
<p>什么是标识符？</p>
</blockquote>
<p>标识符：变量、 函数、 属性或函数参数的名称，可以由<code>一个或多个</code>下列字符组成：</p>
<ul>
<li>第一个必须是字母、下划线或美元符号</li>
<li>剩下其他字符可以是字母、下划线、美元符号或数字</li>
</ul>
<blockquote>
<p>注意：关键字、保留字、true、false、null不能作为标识符</p>
</blockquote>
<h4 id="3-1-3-注释"><a href="#3-1-3-注释" class="headerlink" title="3.1.3 注释"></a>3.1.3 注释</h4><ul>
<li>// 单行注释</li>
<li>/* 多行注释 */</li>
</ul>
<h4 id="3-1-4-严格模式"><a href="#3-1-4-严格模式" class="headerlink" title="3.1.4 严格模式"></a>3.1.4 严格模式</h4><blockquote>
<p>什么是严格模式？</p>
</blockquote>
<p>严格模式：一种不同的<code>JavaScrtip</code>解析和执行模型。对不安全的活动将<code>抛出错误</code>。</p>
<blockquote>
<p>如何使用严格模式？</p>
</blockquote>
<p>在脚本开头加上：<code>&quot;use strict&quot;</code>，表示至此之下的所有代码遵循严格模式，也可以用于<code>块级代码</code>中</p>
<blockquote>
<p>注意事项：</p>
</blockquote>
<p>一般在很多框架中都不推荐使用严格模式，因为会<code>损耗性能</code>。</p>
<h4 id="3-1-5-语句"><a href="#3-1-5-语句" class="headerlink" title="3.1.5 语句"></a>3.1.5 语句</h4><p>ECMAScript中的语句以分号结尾。 省略分号意味着由解析器确定语句在哪里结尾：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> sum = a + b <span class="comment">// 没有分号也有效， 但不推荐</span></span><br><span class="line"><span class="keyword">let</span> diff = a - b; <span class="comment">// 加分号有效， 推荐</span></span><br></pre></td></tr></table></figure>

<h3 id="3-2-关键字与保留字"><a href="#3-2-关键字与保留字" class="headerlink" title="3.2 关键字与保留字"></a>3.2 关键字与保留字</h3><p>ECMA-262描述了一组保留的关键字， 这些关键字有特殊用途.</p>
<blockquote>
<p>ECMA-262第6版规定的所有关键字如下：</p>
</blockquote>
<p>break do in typeof          <br /></p>
<p>case else instanceof var  <br /></p>
<p>catch export new void <br /></p>
<p>class extends return while  <br /></p>
<p>const finally super with  <br /></p>
<p>continue for switch yield <br /></p>
<p>debugger function this  <br /></p>
<p>default if throw  <br /></p>
<p>delete import try <br /></p>
<blockquote>
<p><code>未来的保留字</code>，保留字就是<code>未来将会作为关键字</code>，目前先保留，不予以使用:</p>
</blockquote>
<p>以下是ECMA-262第6版为将来保留的所有词汇。 <br /></p>
<p>  始终保留: <br /></p>
<p>  enum  <br /></p>
<p>  严格模式下保留: <br /></p>
<p>  implements package public <br /></p>
<p>  interface protected static  <br /></p>
<p>  let private <br /></p>
<p>  模块代码中保留: <br /></p>
<p>  await <br /></p>
<h3 id="3-3-变量"><a href="#3-3-变量" class="headerlink" title="3.3 变量"></a>3.3 变量</h3><blockquote>
<p>ECMAScript中的变量与其他语言的变量有什么不同？</p>
</blockquote>
<p>ECMAScript中的变量是<code>松散类型的</code>,即：变量可以保存<code>任何类型的数据</code>【可以理解为：变量就是一个<code>命名占位符</code>】 <br></p>
<blockquote>
<p>有哪些声明变量的方法？</p>
</blockquote>
<h4 id="3-3-1-var"><a href="#3-3-1-var" class="headerlink" title="3.3.1 var"></a>3.3.1 var</h4><blockquote>
<p>使用方法</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> message = <span class="string">&#x27;hello world&#x27;</span>;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>有什么特点?</p>
</blockquote>
<ol>
<li>具有声明作用域：使用<code>var</code>声明变量，会存在于包含它的函数的局部作用域。</li>
</ol>
  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">sayHi</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">  <span class="keyword">var</span> message = <span class="string">&#x27;hi&#x27;</span>;  <span class="comment">// 局部变量</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(message); <span class="comment">//出错</span></span><br></pre></td></tr></table></figure>
  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">sayHello</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">  message = <span class="string">&#x27;hello&#x27;</span>;  <span class="comment">// 全局变量</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(message); <span class="comment">// &quot;Hello&quot;</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>注意：尽量不要使用全局变量，因为不好维护！</p>
</blockquote>
<ol start="2">
<li>声明提升：使用<code>var</code>声明变量，<code>变量的声明</code>会<code>自动提升</code>到<code>该作用域的顶部</code></li>
</ol>
  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">show</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(message);</span><br><span class="line">  <span class="keyword">var</span> message = <span class="string">&#x27;hi&#x27;</span>;</span><br><span class="line">&#125;</span><br><span class="line">show(); <span class="comment">// 输出undefined</span></span><br></pre></td></tr></table></figure>
  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 其实是这样的:</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">show</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">  <span class="keyword">var</span> message;  <span class="comment">// 这就是变量提升（hoist）</span></span><br><span class="line">  <span class="built_in">console</span>.log(message);</span><br><span class="line">  message = <span class="string">&#x27;hi&#x27;</span>;</span><br><span class="line">&#125;</span><br><span class="line">show(); <span class="comment">// 输出undefined</span></span><br></pre></td></tr></table></figure>

<h4 id="3-3-2-let"><a href="#3-3-2-let" class="headerlink" title="3.3.2 let"></a>3.3.2 let</h4><blockquote>
<p>使用方法与<code>var</code>相似</p>
</blockquote>
<blockquote>
<p>有什么特点？</p>
</blockquote>
<ol>
<li><code>let</code>声明的范围是<code>块级作用域</code>,<code>var</code>声明的范围是<code>函数作用域</code>：<br > <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(<span class="literal">true</span>)&#123;</span><br><span class="line">  <span class="keyword">var</span> name = <span class="string">&#x27;zyzc&#x27;</span>;</span><br><span class="line">  <span class="built_in">console</span>.log(name);  <span class="comment">// zyzc</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(name);  <span class="comment">// zyzc</span></span><br><span class="line">      </span><br><span class="line"><span class="keyword">if</span>(<span class="literal">true</span>)&#123;</span><br><span class="line">  <span class="keyword">let</span> message = <span class="string">&#x27;hi&#x27;</span>;</span><br><span class="line">  <span class="built_in">console</span>.log(message); <span class="comment">// hi</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(message); <span class="comment">// 抛出异常：message未定义</span></span><br></pre></td></tr></table></figure></li>
<li>不允许出现冗余【var可以】：<br > <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> name;</span><br><span class="line"><span class="keyword">var</span> name; <span class="comment">//不会报错</span></span><br><span class="line">      </span><br><span class="line"><span class="keyword">let</span> age;  </span><br><span class="line"><span class="keyword">let</span> age;  <span class="comment">// 抛出异常，age已经声明了。</span></span><br></pre></td></tr></table></figure></li>
<li>暂时性死区：<br ><br> let与var的另一个重要的区别， 就是let声明的变量不会在作用域中被提升。<br>   <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// name会被提升</span></span><br><span class="line"><span class="built_in">console</span>.log(name); <span class="comment">// undefined</span></span><br><span class="line"><span class="keyword">var</span> name = <span class="string">&#x27;Matt&#x27;</span>;</span><br><span class="line"><span class="comment">// age不会被提升</span></span><br><span class="line"><span class="built_in">console</span>.log(age); <span class="comment">// ReferenceError： age没有定义</span></span><br><span class="line"><span class="keyword">let</span> age = <span class="number">26</span>;</span><br></pre></td></tr></table></figure>
 在let声明之前的执行瞬间被称为<code>“暂时性死区”（temporal dead zone）</code>,在此阶段引用任何后面才声明的变量都会抛出<code>ReferenceError</code>。</li>
<li>全局声明：<br ><br> 与var关键字不同， 使用let在全局作用域中声明的变量不会成为window对象的属性【<code>var</code>声明的变量则会】   <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> name = <span class="string">&#x27;Matt&#x27;</span>;</span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">window</span>.name); <span class="comment">// &#x27;Matt&#x27;</span></span><br><span class="line"><span class="keyword">let</span> age = <span class="number">26</span>;</span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">window</span>.age); <span class="comment">// undefined</span></span><br></pre></td></tr></table></figure></li>
<li>在<code>for</code>中使用<code>let</code>声明：<br ><br> 使用<code>let</code>声明循环变量，不会<code>渗透到循环以外</code>。   <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="keyword">var</span> j=<span class="number">0</span> ; j&lt;<span class="number">5</span> ; j++)&#123;</span><br><span class="line">  <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> <span class="built_in">console</span>.log(j),<span class="number">0</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 输出 5 5 5 5 5 </span></span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">let</span> i=<span class="number">0</span> ; i&lt;<span class="number">5</span> ; i++)&#123;</span><br><span class="line">  <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> <span class="built_in">console</span>.log(i),<span class="number">0</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 输出 0 1 2 3 4</span></span><br></pre></td></tr></table></figure>
<h4 id="3-3-3-const"><a href="#3-3-3-const" class="headerlink" title="3.3.3 const"></a>3.3.3 const</h4></li>
</ol>
<blockquote>
<p>使用方法与<code>let</code>相似</p>
</blockquote>
<blockquote>
<p><code>const</code>的行为与<code>let</code>基本相似，区别在于<code>const</code>声明的时候<code>必须初始化变量</code>，且<code>后续不可修改</code>。</p>
</blockquote>
<h4 id="3-3-4-注意"><a href="#3-3-4-注意" class="headerlink" title="3.3.4 注意"></a>3.3.4 注意</h4><ul>
<li>不推荐使用var</li>
<li>const优先、let次之。</li>
</ul>
<h3 id="3-4-数据类型"><a href="#3-4-数据类型" class="headerlink" title="3.4 数据类型"></a>3.4 数据类型</h3><blockquote>
<p>有哪些数据类型？</p>
</blockquote>
<ul>
<li>6种简单数据类型（原始类型）：Undefined、Null、Boolean、Number、String、Symbol</li>
<li>1种复杂数据类型：Object【无序名值对的集合】</li>
</ul>
<h4 id="3-4-1-typeof-操作符"><a href="#3-4-1-typeof-操作符" class="headerlink" title="3.4.1 typeof 操作符"></a>3.4.1 typeof 操作符</h4><blockquote>
<p>有什么作用？</p>
</blockquote>
<p>  用来<code>确定</code>任意变量的<code>数据类型</code>：</p>
<blockquote>
<p>如何使用？</p>
</blockquote>
  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> name);</span><br></pre></td></tr></table></figure>
<p>  操作符会返回下列字符串之一：</p>
<ul>
<li>ni”undefined”表示值未定义；</li>
<li>“boolean”表示值为布尔值；</li>
<li>“string”表示值为字符串；</li>
<li>“number”表示值为数值；</li>
<li>“object”表示值为对象（而不是函数） 或null；</li>
<li>“function”表示值为函数；</li>
<li>“symbol”表示值为符号。</li>
</ul>
<blockquote>
<p>注意:null是一个指向空对象的引用。</p>
</blockquote>
<h4 id="3-4-2-Undefined类型"><a href="#3-4-2-Undefined类型" class="headerlink" title="3.4.2 Undefined类型"></a>3.4.2 Undefined类型</h4><blockquote>
<p>Undefined类型只有一个特殊值<code>undefined</code>。当var、let声明未赋值的时候，就会自动赋值undefined</p>
</blockquote>
<blockquote>
<p>注意：</p>
</blockquote>
<ol>
<li><p>未定义与undefined的区别<br></p>
 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> message;</span><br><span class="line"><span class="built_in">console</span>.log(message); <span class="comment">// undefined</span></span><br><span class="line"><span class="built_in">console</span>.log(name); <span class="comment">// 报错</span></span><br></pre></td></tr></table></figure></li>
<li><p>关于某些操作的问题<br></p>
 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> message;</span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> message); <span class="comment">// undefined</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="keyword">typeof</span> name);   <span class="comment">// undefined</span></span><br></pre></td></tr></table></figure>
<blockquote>
<blockquote>
<p>综上可看出，某些操作【typeof delete】会<code>混淆</code>，不知道变量是<code>未初始化</code>还是<code>未声明</code>。<br><br>所以建议<code>在声明变量的时候进行初始化</code>.</p>
</blockquote>
</blockquote>
</li>
<li><p>undefined是一个假值【false】<br></p>
 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> message;</span><br><span class="line"><span class="keyword">if</span>(!message)&#123;</span><br><span class="line">  <span class="comment">// 该模块会执行</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">if</span>(age) &#123;</span><br><span class="line">  <span class="comment">// 会报错</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="3-4-3-Null类型"><a href="#3-4-3-Null类型" class="headerlink" title="3.4.3  Null类型"></a>3.4.3  Null类型</h4><blockquote>
<ol>
<li>Null类型也只有一个特殊值:<code>null</code>，表示一个<code>空对象指针</code></li>
</ol>
</blockquote>
</li>
</ol>
<blockquote>
<ol start="2">
<li>当定义对象，又未确定对象内容时，建议使用<code>null</code>来初始化</li>
</ol>
</blockquote>
<blockquote>
<ol start="3">
<li>null也是一个假值</li>
</ol>
</blockquote>
<h4 id="3-4-4-Boolean类型"><a href="#3-4-4-Boolean类型" class="headerlink" title="3.4.4 Boolean类型"></a>3.4.4 Boolean类型</h4><blockquote>
<p>Boolean有两个字面值<code>true</code>、<code>false</code>。</p>
</blockquote>
<blockquote>
<p>Boolean()转型函数，转换规则如下：</p>
</blockquote>
<table>
  <tr>
    <td>数据类型</td>
    <td>Boolean</td>
    <td>String</td>
    <td>Number</td>
    <td>Object</td>
    <td>Undefined</td>
  </tr>
    <td>转换为true的值</td>
    <td>true</td>
    <td>非空字符串</td>
    <td>非零数值（包括Infinity）</td>
    <td>任意对象</td>
    <td>不存在</td>
  <tr>
  </tr>
    <td>转换为false的值</td>
    <td>false</td>
    <td>""(空字符串)</td>
    <td>0、NaN</td>
    <td>null</td>
    <td>undefined</td>
  <tr>
  </tr>
</table>

<blockquote>
<p>在<code>控制语句</code>中，参考变量会<code>自动转换</code><br>  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> message = <span class="string">&#x27;hi&#x27;</span>;</span><br><span class="line"><span class="keyword">if</span>(message)&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">&quot;this value is real&quot;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
</blockquote>
<h4 id="3-4-5-Number类型"><a href="#3-4-5-Number类型" class="headerlink" title="3.4.5 Number类型"></a>3.4.5 Number类型</h4><blockquote>
<p>Number使用IEEE 754格式表示<code>整数</code>、<code>浮点数</code></p>
</blockquote>
<blockquote>
<p>Number中的进制</p>
<ol>
<li><p>基本是十进制</p>
</li>
<li><p>0开头表示八进制</p>
 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = <span class="number">070</span>; <span class="comment">// 表示56</span></span><br><span class="line"><span class="keyword">let</span> num2 = <span class="number">078</span>; <span class="comment">// 无效八进制数，表示78</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>0x开头表示十六进制</p>
 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num2 = <span class="number">0xA</span>; <span class="comment">//表示10</span></span><br><span class="line"><span class="keyword">let</span> num3 = <span class="number">0x1f</span>;  <span class="comment">//表示31</span></span><br></pre></td></tr></table></figure>
<p> 浮点值：【存储空间是整数的<code>两倍</code>】</p>
</li>
<li><p>如何使用浮点值:<br></p>
 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = <span class="number">1.1</span>;</span><br><span class="line"><span class="keyword">let</span> num2 = <span class="number">0.1</span>; </span><br></pre></td></tr></table></figure>
</li>
<li><p>小数点后面必须有非零值:<br></p>
 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num3 = <span class="number">10.0</span>;  <span class="comment">//会被当成整数10处理</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>科学记数法<br></p>
 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num4 = <span class="number">3.14e5</span>;  <span class="comment">//表示3.14*10^5</span></span><br><span class="line"><span class="keyword">let</span> num5 = <span class="number">3.14e-5</span>;  <span class="comment">//表示3.14*10^-5</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>ECMAScript会将<code>包含6个零</code>的浮点数转换为<code>科学记数法</code><br></p>
</li>
<li><p>浮点精度高达<code>17位</code><br></p>
</li>
<li><p>由于算数的底层是二进制的操作，会出现<code>浮点精度丢失</code><br></p>
 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>( <span class="number">0.1</span> + <span class="number">0.2</span> == <span class="number">0.3</span> )&#123;</span><br><span class="line">    <span class="comment">// 代码进不来，因为0.1+0.2不等于0.3</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 0.1的二进制表示：0.0001 1001 1001 1001 1001 10</span></span><br><span class="line"><span class="comment">// 0.2的二进制表示：0.0011 0011 0011 0011 0011 00</span></span><br><span class="line"><span class="comment">// 0.1 + 0.2     ：0.0100 1100 1100 1100 1100 10  = 0.300 000 000 000 000 000 04</span></span><br></pre></td></tr></table></figure>
<p> 小数点如何转化为二进制？</p>
   <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 不断×2并提取个位数</span></span><br><span class="line"><span class="comment">// 0.1 * 2 = 0.2  0</span></span><br><span class="line"><span class="comment">// 0.2 * 2 = 0.4  0</span></span><br><span class="line"><span class="comment">// 0.4 * 2 = 0.8  0</span></span><br><span class="line"><span class="comment">// 0.8 * 2 = 1.6  1</span></span><br><span class="line"><span class="comment">// 0.6 * 2 = 1.2  1</span></span><br><span class="line"><span class="comment">// .......</span></span><br></pre></td></tr></table></figure></li>
</ol>
</blockquote>
<ol start="7">
<li>值的范围<br><ul>
<li>最小值：Number.MIN_VALUE(大多数浏览器中是<code>5e-324</code>);</li>
<li>最大值：Number.MAX_VALUE(大多数浏览器中是<code>1.7976931348623157e+308</code>)</li>
<li>如果超出最大最小值，则为：`-Infinity``Infinity</li>
<li>可以使用<code>isFinite()</code>函数判断该值是否是无穷</li>
</ul>
</li>
<li>NaN（Not a Number）<br><blockquote>
<p>表示不是数值，用于本来要求<code>返回数值的操作失败</code>了（<code>而不是抛出错误</code>）</p>
</blockquote>
</li>
</ol>
<blockquote>
<p>NaN有如下特性：</p>
</blockquote>
<ul>
<li>任何涉及NaN的操作始终返回NaN</li>
<li>NaN不等于包括NaN在内的任何值</li>
</ul>
<ol start="9">
<li>数值转换<br></li>
</ol>
<blockquote>
<p>Number()规则：</p>
</blockquote>
<ul>
<li>布尔值： true-&gt;1 false-&gt;0</li>
<li>数值：直接返回</li>
<li>null：返回0</li>
<li>undefined：返回NaN</li>
<li>字符串：<ul>
<li>出现<code>十进制</code>、<code>八进制</code>、<code>十六进制</code>的数字，则忽略零返回数值</li>
<li>空字符串-&gt;0</li>
<li>出现其他字符，返回NaN</li>
</ul>
</li>
<li>对象：调用<code>valueOf()</code>，然后按照上述规则转换。如果转换结果是NaN，则调用<code>toString()</code>转换后，再按照字符串的规则转换。</li>
</ul>
<blockquote>
<p>parseInt()【也可以识别2、8、16进制】</p>
</blockquote>
<ul>
<li><p>原理：忽略零，从<code>第一个非空格字符</code>开始转换，如果第一个非空字符不是<code>数字、加号、减号</code>则立马返回NaN；否则一直向后检索，直到<code>字符串末尾</code>或者遇到<code>非数字字符</code>。然后返回整数。</p>
</li>
<li><p>函数使用：<code>parseInt(&quot;num&quot;,进制)</code>；</p>
  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 为了防止函数解析出错，推荐传第二个参数。</span></span><br><span class="line">  <span class="keyword">let</span> num1 = <span class="built_in">parseInt</span>(<span class="string">&quot;10&quot;</span>,<span class="number">2</span>);  <span class="comment">// 2</span></span><br><span class="line">  <span class="keyword">let</span> num2 = <span class="built_in">parseInt</span>(<span class="string">&quot;10&quot;</span>,<span class="number">10</span>); <span class="comment">// 10</span></span><br><span class="line">  <span class="keyword">let</span> num3 = <span class="built_in">parseInt</span>(<span class="string">&quot;10&quot;</span>,<span class="number">16</span>); <span class="comment">// 16</span></span><br></pre></td></tr></table></figure></li>
</ul>
<blockquote>
<p>parseFloat()</p>
</blockquote>
<p>  与<code>parseInt()</code>工作原理类似，但是只能识别<code>10进制</code>，<code>16进制</code>始终返回0。</p>
<h4 id="3-4-6-String类型"><a href="#3-4-6-String类型" class="headerlink" title="3.4.6 String类型"></a>3.4.6 String类型</h4><blockquote>
<p>如何使用?</p>
</blockquote>
  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> name = <span class="string">&#x27;zyzc&#x27;</span>;</span><br><span class="line"><span class="keyword">let</span> sex = <span class="string">&quot;男&quot;</span>;</span><br><span class="line"><span class="keyword">let</span> message = <span class="string">`hello world`</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>字符字面量:</p>
</blockquote>
<ul>
<li>\n  换行</li>
<li>\t  制表</li>
<li>\b  退格</li>
<li>\r  回车</li>
<li>\f  换页</li>
<li>\  反斜杠</li>
<li>&#39;  单引号</li>
<li>&quot;  双引号</li>
<li>`  反引号</li>
<li>\xnn  n表示为16进制数字，表达字符【代表一个字符长度】</li>
<li>\unnnn  n表示为16进制数字，表达Unicode字符【代表一个字符长度】</li>
</ul>
<blockquote>
<p>字符串特点:</p>
</blockquote>
<p>  ECMAScript中，字符串是<code>不可变的</code>。一旦被创建，值不能改变，如果要改变，就会经过销毁、创建的过程。所以<code>早期的浏览器</code>字符串拼接<code>非常慢</code>.</p>
<blockquote>
<p>字符串转换：</p>
</blockquote>
<ol>
<li><p>使用toString(),对<code>null</code>、<code>undefined</code>无效<br></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> age = <span class="number">11</span>;</span><br><span class="line"><span class="keyword">let</span> ageString = age.toString(); <span class="comment">// &quot;11&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> flag = <span class="literal">true</span>;</span><br><span class="line"><span class="keyword">let</span> flagString = flag.toString(); <span class="comment">// &quot;true&quot;</span></span><br></pre></td></tr></table></figure></li>
</ol>
<blockquote>
<p>当数值调用toString(),也可以接收第二个参数【默认为10】。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num = <span class="number">10</span>;</span><br><span class="line">num.toString();     / <span class="string">&quot;10&quot;</span></span><br><span class="line">num.toString(<span class="number">2</span>);  / <span class="string">&quot;1010&quot;</span></span><br><span class="line">num.toString(<span class="number">8</span>);  / <span class="string">&quot;12&quot;</span></span><br><span class="line">num.toString(<span class="number">16</span>); / <span class="string">&quot;a&quot;</span></span><br></pre></td></tr></table></figure>
</blockquote>
<ol start="2">
<li><p>使用String()<br></p>
<ul>
<li>对null使用，返回”null”</li>
<li>对undefined使用，返回”undefined”</li>
<li>其他与<code>toString()</code>差不多</li>
</ul>
</li>
</ol>
<blockquote>
<p>模板字面量【反引号】<br></p>
</blockquote>
<p>  与单引号、双引号不同，<code>模板字面量</code>保留换行字符。</p>
<blockquote>
<p>字符串插值</p>
</blockquote>
<ol>
<li>使用方法：${ 变量 }</li>
<li>原理：所插入的<code>变量</code>，都会通过<code>toString()</code>强制转换为字符串</li>
</ol>
<blockquote>
<p>模板字面量标签函数</p>
</blockquote>
<p>  可以通过<code>标签函数</code>自定义<code>插值行为</code>，<code>标签函数</code>会接收被插值记号<code>分割后的模板</code>、以及每个<code>表达式的求值结果</code>.</p>
  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> a = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">let</span> b = <span class="number">2</span>;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">simpleTag</span>(<span class="params">strings,...expressions</span>)</span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(strings); <span class="comment">//[&quot;&quot;,&quot; + &quot;,&quot; = &quot;,&quot;&quot;]</span></span><br><span class="line">  <span class="keyword">for</span>(<span class="keyword">const</span> expression <span class="keyword">of</span> expressions)&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(expression);  <span class="comment">//分别是 1 2 3</span></span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> <span class="string">&#x27;success&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> untaggedResult = <span class="string">`<span class="subst">$&#123; a &#125;</span> + <span class="subst">$&#123; b &#125;</span> = <span class="subst">$&#123; a+b &#125;</span>`</span>;</span><br><span class="line"><span class="keyword">let</span> taggedResult = simpleTag<span class="string">`<span class="subst">$&#123; a &#125;</span> + <span class="subst">$&#123; b &#125;</span> = <span class="subst">$&#123; a+b &#125;</span>`</span>;</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(untaggedResult); <span class="comment">// 1 + 2 = 3</span></span><br><span class="line"><span class="built_in">console</span>.log(taggedResult);  <span class="comment">// success</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>原始字符串</p>
</blockquote>
  <pre>使用String.raw`字符串`可以获取原始的模板字面量</pre>


<h4 id="3-4-7-Symbol类型"><a href="#3-4-7-Symbol类型" class="headerlink" title="3.4.7 Symbol类型"></a>3.4.7 Symbol类型</h4><blockquote>
<p>什么是Symbol</p>
</blockquote>
<p>  用于确保对象属性的<code>唯一性</code>标识符。</p>
<blockquote>
<p>如何使用Symbol</p>
</blockquote>
  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 1. 调用的时候可以传参，但是找个字符串参数与符号定义、符号标识无关</span></span><br><span class="line"><span class="comment">// 2. 不能使用new进行调用</span></span><br><span class="line">  <span class="keyword">let</span> myAge = <span class="built_in">Symbol</span>();</span><br><span class="line">  <span class="keyword">let</span> hisAge = <span class="built_in">Symbol</span>();</span><br><span class="line">  <span class="keyword">let</span> myName = <span class="built_in">Symbol</span>(<span class="string">&#x27;username&#x27;</span>);</span><br><span class="line">  <span class="keyword">let</span> hisName = <span class="built_in">Symbol</span>(<span class="string">&#x27;username&#x27;</span>);</span><br><span class="line"></span><br><span class="line">  <span class="built_in">console</span>.log(myName == hisName)  <span class="comment">//false</span></span><br><span class="line">  <span class="built_in">console</span>.log(myName == hisName)  <span class="comment">//false</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>使用全局符号注册表</p>
</blockquote>
<ol>
<li>怎样使用？</li>
</ol>
  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> fooGlobalSymbol = <span class="built_in">Symbol</span>.for(<span class="string">&quot;foo&quot;</span>);</span><br><span class="line"><span class="comment">// 注册全局符号是唯一且可以重用的</span></span><br><span class="line"><span class="comment">// 因为每次调用.for()都会检索注册表，不存在着创建，存在则重用。</span></span><br><span class="line"><span class="keyword">let</span> otherFooGlobalSymbol = <span class="built_in">Symbol</span>.for(<span class="string">&quot;foo&quot;</span>);</span><br><span class="line"><span class="built_in">console</span>.log(fooGlobalSymbol == otherFooGlobalSymbol); <span class="comment">//true</span></span><br></pre></td></tr></table></figure>

<ol start="2">
<li>怎样寻找？</li>
</ol>
  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> n = <span class="built_in">Symbol</span>.for(<span class="string">&#x27;name&#x27;</span>);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Symbol</span>.keyFor(n));  <span class="comment">//name</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>符号也可以作为对象的属性，从而达到属性唯一的功能。</p>
</blockquote>
<h4 id="3-4-8-Object类型"><a href="#3-4-8-Object类型" class="headerlink" title="3.4.8 Object类型"></a>3.4.8 Object类型</h4><blockquote>
<p>Object就是数据和功能的集合。</p>
</blockquote>
<blockquote>
<p>怎样使用?<br>  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> o = <span class="keyword">new</span> <span class="built_in">Object</span>();</span><br></pre></td></tr></table></figure></p>
</blockquote>
<blockquote>
<p>每个对象都有如下属性和方法：</p>
</blockquote>
<ul>
<li>constructor : 用于创建当前对象</li>
<li>hasOwnProperty(propertyName) : 用于判断对象是否存在给定属性</li>
<li>isPrototypeOf(object) : 用于判定对象是否为另一个对象的原型</li>
<li>propertyIsEnumerable(propertyName) : 用于判定给定属性是否可以使用 </li>
<li>toLocaleString() : 返回对象的字符串标识</li>
<li>valueOf() ： 返回对象的字符串、数值、布尔值表示</li>
</ul>
<h3 id="3-5-操作符"><a href="#3-5-操作符" class="headerlink" title="3.5 操作符"></a>3.5 操作符</h3><h4 id="3-5-1-一元操作符"><a href="#3-5-1-一元操作符" class="headerlink" title="3.5.1 一元操作符"></a>3.5.1 一元操作符</h4><ol>
<li>递增、递减<blockquote>
<p>用（++、–）表示</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> age = <span class="number">18</span>;</span><br><span class="line">++age;  <span class="comment">// age=19 先递增</span></span><br><span class="line">age++;  <span class="comment">// age=19 先使用、后递增、、</span></span><br><span class="line"><span class="built_in">console</span>.log(age); <span class="comment">//age=20</span></span><br></pre></td></tr></table></figure></li>
<li>加、减<blockquote>
<p>用（+、-）表示数值的<code>正、负</code></p>
</blockquote>
</li>
</ol>
<h4 id="3-5-2-位操作符"><a href="#3-5-2-位操作符" class="headerlink" title="3.5.2 位操作符"></a>3.5.2 位操作符</h4><blockquote>
<p>位操作是数值操作的<code>底层操作</code>，虽然数值以64位的格式存储，但是位操作只能是32位的操作。所以在ECMAScript中，先将64转为32，操作后，再转为64。</p>
</blockquote>
<blockquote>
<p>分类：</p>
</blockquote>
<ol>
<li><p>按位非</p>
<blockquote>
<p>用（~）表示。0-&gt;1 或 1-&gt;0</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = <span class="number">25</span>;    <span class="comment">//0000 0000 0000 0000 0000 0000 0001 1001</span></span><br><span class="line"><span class="keyword">let</span> num2 = ~num1; <span class="comment">//1111 1111 1111 1111 1111 1111 1110 0110</span></span><br><span class="line"><span class="built_in">console</span>.log(num2);  <span class="comment">// -26</span></span><br><span class="line"><span class="comment">// 虽然说-num1-1=-26，但是位操作速度快得多</span></span><br></pre></td></tr></table></figure></li>
<li><p>按位与</p>
</li>
</ol>
<blockquote>
<p>用（&amp;）表示。</p>
</blockquote>
<blockquote>
<p>真值表：</p>
</blockquote>
  <table>
    <tr>
      <td>第一个数值的位</td>
      <td>第二个数值的位</td>
      <td>结果</td>
    </tr>
    <tr>
      <td>1</td>
      <td>1</td>
      <td>1</td>
    </tr>
    <tr>
      <td>1</td>
      <td>0</td>
      <td>0</td>
    </tr>
    <tr>
      <td>0</td>
      <td>1</td>
      <td>0</td>
    </tr>
    <tr>
      <td>0</td>
      <td>0</td>
      <td>0</td>
    </tr>
  </table>
  3. 按位或

<blockquote>
<p>用（|）表示。</p>
</blockquote>
<blockquote>
<p>真值表：</p>
</blockquote>
  <table>
    <tr>
      <td>第一个数值的位</td>
      <td>第二个数值的位</td>
      <td>结果</td>
    </tr>
    <tr>
      <td>1</td>
      <td>1</td>
      <td>1</td>
    </tr>
    <tr>
      <td>1</td>
      <td>0</td>
      <td>1</td>
    </tr>
    <tr>
      <td>0</td>
      <td>1</td>
      <td>1</td>
    </tr>
    <tr>
      <td>0</td>
      <td>0</td>
      <td>0</td>
    </tr>
  </table>
  4. 按位异或

<blockquote>
<p>用（^）表示。</p>
</blockquote>
<blockquote>
<p>真值表：</p>
</blockquote>
  <table>
    <tr>
      <td>第一个数值的位</td>
      <td>第二个数值的位</td>
      <td>结果</td>
    </tr>
    <tr>
      <td>1</td>
      <td>1</td>
      <td>0</td>
    </tr>
    <tr>
      <td>1</td>
      <td>0</td>
      <td>1</td>
    </tr>
    <tr>
      <td>0</td>
      <td>1</td>
      <td>1</td>
    </tr>
    <tr>
      <td>0</td>
      <td>0</td>
      <td>0</td>
    </tr>
  </table>

<ol start="5">
<li>左移</li>
</ol>
<blockquote>
<p>用（&lt;&lt;）表示。<code>符号位不受影响，空位由0补充</code><br>  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> beforeValue = <span class="number">2</span>;                <span class="comment">// 10</span></span><br><span class="line"><span class="keyword">let</span> afterValue = beforeValue &lt;&lt; <span class="number">5</span>;  <span class="comment">// 100 0000 即 64</span></span><br></pre></td></tr></table></figure><br>  6. 有符号右移</p>
</blockquote>
<blockquote>
<p>用（&gt;&gt;）表示。<code>符号位不动，空位由符号位填充</code><br>  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> beforeValue = <span class="number">64</span>;                <span class="comment">// 100 0000</span></span><br><span class="line"><span class="keyword">let</span> afterValue = beforeValue &gt;&gt; <span class="number">5</span>;  <span class="comment">// 10 即 2</span></span><br></pre></td></tr></table></figure></p>
</blockquote>
<ol start="7">
<li>无符号右移</li>
</ol>
<blockquote>
<p>用（&gt;&gt;&gt;）表示。<code>符号位动，空位由0填充</code><br>  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> beforeValue = <span class="number">64</span>;                <span class="comment">// 100 0000</span></span><br><span class="line"><span class="keyword">let</span> afterValue = beforeValue &gt;&gt;&gt; <span class="number">5</span>;  <span class="comment">// 10 即 2</span></span><br></pre></td></tr></table></figure><br>由于符号位也跟着动，所以对于负数而言，变化很大。<br>  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> beforeValue = -<span class="number">64</span>;                <span class="comment">// 1111 1111 1111 1111 1111 1111 1100 0000</span></span><br><span class="line"><span class="keyword">let</span> afterValue = beforeValue &gt;&gt;&gt; <span class="number">5</span>;  <span class="comment">//  0000 0111 1111 1111 1111 1111 1111 1110 = 134217726</span></span><br></pre></td></tr></table></figure></p>
</blockquote>
<h4 id="3-5-3-布尔操作符"><a href="#3-5-3-布尔操作符" class="headerlink" title="3.5.3 布尔操作符"></a>3.5.3 布尔操作符</h4><ol>
<li>逻辑非<blockquote>
<p>用（！）表示，用于<code>取反值</code></p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">console</span>.log(!<span class="literal">false</span>); <span class="comment">// true</span></span><br><span class="line"><span class="built_in">console</span>.log(!<span class="string">&quot;blue&quot;</span>); <span class="comment">// false</span></span><br><span class="line"><span class="built_in">console</span>.log(!<span class="number">0</span>); <span class="comment">// true</span></span><br><span class="line"><span class="built_in">console</span>.log(!<span class="literal">NaN</span>); <span class="comment">// true</span></span><br><span class="line"><span class="built_in">console</span>.log(!<span class="string">&quot;&quot;</span>); <span class="comment">// true</span></span><br><span class="line"><span class="built_in">console</span>.log(!<span class="number">12345</span>); <span class="comment">// false</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p><code>逻辑非</code>遵循如下规则：</p>
</blockquote>
</li>
</ol>
<ul>
<li>如果操作数是<code>对象</code>， 则返回false。</li>
<li>如果操作数是<code>空字符串</code>， 则返回true。</li>
<li>如果操作数是<code>非空字符串</code>， 则返回false。</li>
<li>如果操作数是<code>数值0</code>， 则返回true。</li>
<li>如果操作数是<code>非0数值（包括Infinity）</code> ， 则返回false。</li>
<li>如果操作数是<code>null</code>， 则返回true。</li>
<li>如果操作数是<code>NaN</code>， 则返回true。</li>
<li>如果操作数是<code>undefined</code>， 则返回true。</li>
</ul>
<ol start="2">
<li>逻辑与<blockquote>
<p>用（&amp;&amp;）表示。</p>
</blockquote>
</li>
</ol>
  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> result = a &amp;&amp; b;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>真值表：<br>  <table><br>    <tr><br>      <td>第一个操作数</td><br>      <td>第二个操作数</td><br>      <td>结果</td><br>    </tr><br>    <tr><br>      <td>true</td><br>      <td>true</td><br>      <td>true</td><br>    </tr><br>    <tr><br>      <td>true</td><br>      <td>false</td><br>      <td>false</td><br>    </tr><br>    <tr><br>      <td>false</td><br>      <td>true</td><br>      <td>false</td><br>    </tr><br>    <tr><br>      <td>false</td><br>      <td>false</td><br>      <td>false</td><br>    </tr><br>  </table></p>
</blockquote>
<blockquote>
<p><code>逻辑与</code>遵循如下规则：</p>
</blockquote>
<ul>
<li>如果第一个操作数是对象， 则返回第二个操作数。</li>
<li>如果第二个操作数是对象， 则只有第一个操作数求值为true才会返回该对象。</li>
<li>如果两个操作数都是对象， 则返回第二个操作数。</li>
<li>如果有一个操作数是null， 则返回null。</li>
<li>如果有一个操作数是NaN， 则返回NaN。</li>
<li>如果有一个操作数是undefined， 则返回undefined。</li>
</ul>
<ol start="3">
<li>逻辑或</li>
</ol>
<blockquote>
<p>用（||）表示。<br>   <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> result = a || b;</span><br></pre></td></tr></table></figure></p>
</blockquote>
<blockquote>
<p>真值表：<br>  <table><br>    <tr><br>      <td>第一个操作数</td><br>      <td>第二个操作数</td><br>      <td>结果</td><br>    </tr><br>    <tr><br>      <td>true</td><br>      <td>true</td><br>      <td>true</td><br>    </tr><br>    <tr><br>      <td>true</td><br>      <td>false</td><br>      <td>true</td><br>    </tr><br>    <tr><br>      <td>false</td><br>      <td>true</td><br>      <td>true</td><br>    </tr><br>    <tr><br>      <td>false</td><br>      <td>false</td><br>      <td>false</td><br>    </tr><br>  </table></p>
</blockquote>
<blockquote>
<p><code>逻辑或</code>遵循如下规则：</p>
</blockquote>
<ul>
<li>如果第一个操作数是对象， 则返回第一个操作数。</li>
<li>如果第一个操作数求值为false， 则返回第二个操作数。</li>
<li>如果两个操作数都是对象， 则返回第一个操作数。</li>
<li>如果两个操作数都是null， 则返回null。</li>
<li>如果两个操作数都是NaN， 则返回NaN。</li>
<li>如果两个操作数都是undefined， 则返回undefined。</li>
</ul>
<h4 id="3-5-4-乘性操作符"><a href="#3-5-4-乘性操作符" class="headerlink" title="3.5.4 乘性操作符"></a>3.5.4 乘性操作符</h4><ol>
<li>乘法操作符<blockquote>
<p>用（*）表示，用于计算两个数值的<code>乘积</code>;</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> result = <span class="number">3</span> * <span class="number">2</span>;   <span class="comment">//6</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p><code>乘法操作符</code>有如下<code>特殊情况</code>：</p>
</blockquote>
</li>
</ol>
<ul>
<li>如果两个操作数都是数值，则执行数学减法运算并返回结果。</li>
<li>如果有<code>任一操作数</code>是<code>NaN</code>，则<code>返回NaN</code>。</li>
<li>如果是Infinity减Infinity，则返回NaN。</li>
<li>如果是-Infinity减-Infinity，则返回NaN。</li>
<li>如果是Infinity减-Infinity，则返回Infinity。</li>
<li>如果是-Infinity减Infinity，则返回-Infinity。</li>
<li>如果是+0减+0，则返回+0。</li>
<li>如果是+0减-0，则返回-0。</li>
<li>如果是-0减-0，则返回+0。</li>
<li>如果有<code>任一操作数</code>是<code>字符串、布尔值、null或undefined</code>，则先在后台<code>使用Number()将其转换为数值</code>，然后再根据前面的规则执行数学运算。如果<code>转换结果是NaN</code>，则减法计算的<code>结果是NaN</code>。</li>
<li>如果有<code>任一操作数</code>是<code>对象</code>，则<code>调用其valueOf()方法取得表示它的数</code>值。如果该值是NaN，则减法计算的结果是NaN。如果对象<code>没有valueOf()方法</code>，则<code>调用其toString()方法</code>，然后再将得到的字符串转换为数值。</li>
</ul>
<ol start="2">
<li>除法操作符<blockquote>
<p>用（/）表示，用于计算第一个操作数除以第二个操作数的商</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> result = <span class="number">66</span> / <span class="number">11</span>;  <span class="comment">//6;</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p><code>除法操作符</code>有如下<code>特殊情况</code>：</p>
</blockquote>
</li>
</ol>
<ul>
<li>如果操作数都是数值， 则执行常规的除法运算。如果ECMAScript不能表示的商，则返回Infinity或-Infinity。</li>
<li>如果有<code>任一操作数</code>是<code>NaN</code>， 则返回<code>NaN</code>。</li>
<li>如果是<code>Infinity除以Infinity</code>， 则返回<code>NaN</code>。</li>
<li>如果是<code>0除以0</code>， 则返回<code>NaN</code>。</li>
<li>如果是<code>非0的有限值除以0</code>， 则根据<code>第一个操作数的符号</code>返回Infinity或-Infinity。</li>
<li>如果是<code>Infinity除以任何数值</code>， 则根据<code>第二个操作数的符号</code>返回Infinity或-Infinity。</li>
<li>如果有不是数值的操作数， 则先在后台用Number()函数将其转换为数值，然后再应用上述规则。</li>
</ul>
<ol start="3">
<li>取模操作符<blockquote>
<p>用（%）表示，用于获取第一个操作数除以第二个操作数后的<code>余数</code></p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> result = <span class="number">26</span> % <span class="number">5</span> ; <span class="comment">// 1</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p><code>取模操作符</code>有如下特殊情况：</p>
</blockquote>
</li>
</ol>
<ul>
<li>如果操作数是数值， 则执行常规除法运算， 返回余数。</li>
<li>如果被除数是<code>无限值</code>， 除数是<code>有限值</code>， 则返回<code>NaN</code>。</li>
<li>如果被除数是<code>有限值</code>， 除数是<code>0</code>， 则返回<code>NaN</code>。</li>
<li>如果是<code>Infinity除以Infinity</code>， 则返回<code>NaN</code>。</li>
<li>如果被除数是<code>有限值</code>， 除数是<code>无限值</code>， 则返回<code>被除数</code>。</li>
<li>如果<code>被除数是0</code>， <code>除数不是0</code>， 则返回<code>0</code>。</li>
<li>如果有<code>不是数值</code>的操作数，则先在后台<code>用Number()函数</code>将其<code>转换为数值</code>，然后再应用上述规则。</li>
</ul>
<h4 id="3-5-5-指数操作符"><a href="#3-5-5-指数操作符" class="headerlink" title="3.5.5 指数操作符"></a>3.5.5 指数操作符</h4><blockquote>
<p>ECMAScript 7中新增了<code>指数操作符（**）</code>。</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> result1 = <span class="built_in">Math</span>.pow(<span class="number">3</span>,<span class="number">2</span>);  <span class="comment">//9</span></span><br><span class="line"><span class="keyword">let</span> result2 = <span class="number">3</span> ** <span class="number">2</span>; <span class="comment">// 9</span></span><br></pre></td></tr></table></figure>

<h4 id="3-5-6-加性操作符"><a href="#3-5-6-加性操作符" class="headerlink" title="3.5.6 加性操作符"></a>3.5.6 加性操作符</h4><ol>
<li>加法操作符<blockquote>
<p>加法操作符（+）用于求两个数的和：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> result = <span class="number">1</span> + <span class="number">2</span>;</span><br></pre></td></tr></table></figure>
<blockquote>
<p><code>两个数值</code>的加法操作符遵循如下规则：</p>
</blockquote>
</li>
</ol>
<ul>
<li>如果有任一操作数是NaN， 则返回NaN；</li>
<li>如果是Infinity加Infinity， 则返回Infinity；</li>
<li>如果是-Infinity加-Infinity， 则返回-Infinity；</li>
<li>如果是Infinity加-Infinity， 则返回NaN；</li>
<li>如果是+0加+0， 则返回+0；</li>
<li>如果是-0加+0， 则返回+0；</li>
<li>如果是-0加-0， 则返回-0。<blockquote>
<p>如果有一个操作数是字符串， 则要遵循如下规则：</p>
</blockquote>
</li>
<li>如果两个操作数都是字符串， 则将第二个字符串拼接到第一个字符串后面；</li>
<li>如果只有一个操作数是字符串， 则将另一个操作数转换为字符串， 再将两个字符串拼接在一起。</li>
</ul>
<ol start="2">
<li>减法操作符<blockquote>
<p>减法操作符（-）用于求差：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> result = <span class="number">2</span> - <span class="number">1</span>;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>与<code>加法操作符</code>一致，<code>减法操作符</code>遵循如下规则：</p>
</blockquote>
</li>
</ol>
<ul>
<li>如果两个操作数都是数值，则执行数学减法运算并返回结果。</li>
<li>如果有任一操作数是NaN，则返回NaN。</li>
<li>如果是Infinity减Infinity，则返回NaN。</li>
<li>如果是-Infinity减-Infinity，则返回NaN。</li>
<li>如果是Infinity减-Infinity，则返回Infinity。</li>
<li>如果是-Infinity减Infinity，则返回-Infinity。</li>
<li>如果是+0减+0，则返回+0。</li>
<li>如果是+0减-0，则返回-0。</li>
<li>如果是-0减-0，则返回+0。</li>
<li>如果<code>有任一操作数是字符串、布尔值、null或undefined</code>，则先在后台使用<code>Number()</code>将其<code>转换为数值</code>，然后再根据前面的规则执行数学运算。如果转换结果是NaN，则减法计算的结果是NaN。</li>
<li>如果<code>有任一操作数是对象</code>，则调用其<code>valueOf()</code>方法<code>取得表示它的数值</code>。如果该值是NaN，则减法计算的结果是NaN。如果对象<code>没有valueOf()方法</code>，则<code>调用其toString()方法</code>，然后再将得到的<code>字符串转换为数值</code>。</li>
</ul>
<h4 id="3-5-7-关系操作符"><a href="#3-5-7-关系操作符" class="headerlink" title="3.5.7 关系操作符"></a>3.5.7 关系操作符</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 使用方法</span></span><br><span class="line">  <span class="keyword">let</span> a = <span class="number">1</span>;</span><br><span class="line">  <span class="keyword">let</span> b = <span class="number">2</span>;</span><br><span class="line">  <span class="keyword">if</span>(a &gt; b)&#123;</span><br><span class="line"></span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>包括&gt;、&lt;、&gt;=、&lt;=;这几个操作符都返回布尔值</p>
</blockquote>
<blockquote>
<p>比较规则：</p>
</blockquote>
<ul>
<li>如果操作数都是数值， 则执行数值比较。</li>
<li>如果操作数<code>都是字符串</code>， 则<code>逐个比较</code>字符串中<code>对应字符的编码</code>。</li>
<li>如果有任一操作数是<code>数值</code>， 则将<code>另一个操作数转换为数值</code>， 执行数值比较。</li>
<li>如果有任一操作数是<code>对象</code>， 则<code>调用其valueOf()方法</code>， 取得结果后再根据前面的规则执行比较。 如果<code>没有valueOf()操作符</code>， 则<code>调用toString()方法</code>， 取得结果后再根据前面的规则执行比较。</li>
<li>如果有任一操作数是<code>布尔值</code>， 则将其<code>转换为数值</code>再执行比较。</li>
</ul>
<h4 id="3-5-8-相等操作符"><a href="#3-5-8-相等操作符" class="headerlink" title="3.5.8 相等操作符"></a>3.5.8 相等操作符</h4>  <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(num1 == num2 ) &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">&quot;这两个值相等&quot;</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">if</span>(num1 != num2 ) &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">&quot;这两个值不相等&quot;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>等于和不等于【使用前，会对待比较的两个值进行<code>强制类型转换</code>】</p>
</blockquote>
<blockquote>
<p>比较规则：</p>
</blockquote>
<ul>
<li>如果任一操作数是<code>布尔值</code>，则将其<code>转换为数值</code>再比较是否相等。<code>false转换为0， true转换为1</code>。</li>
<li>如果一个操作数是<code>字符串</code>，另一个操作数是数值，则尝试将<code>字符串转换为数值</code>，再比较是否相等。</li>
<li> 如果一个操作数是<code>对象</code>，另一个操作数不是，则<code>调用对象的valueOf()方法取得其原始值</code>，再根据前面的规则进行比较。在进行比较时，这两个操作符会遵循如下规则:    * <code>null</code>和<code>undefined</code>相等。    * <code>null</code>和<code>undefined</code>不能转换为其他类型的值再进行比较。</li>
<li>如果有任一操作数是NaN，则相等操作符返回false，不相等操作符返回true。记住： 即使两个操作数都是NaN，相等操作符也返回false，因为按照规则，<code>NaN不等于NaN</code>。</li>
<li>如果<code>两个操作数都是对象</code>，则比较它们是不是同一个对象。 </li>
<li>如果<code>两个操作数都指向同一个对象</code>，则相等操作符<code>返回true</code>。否则，两者不相等。</li>
</ul>
<blockquote>
<p>特殊比较结果：</p>
</blockquote>
<pre><code>null == undefined true
&quot;NaN&quot; == NaN false
5 == NaN false
NaN == NaN false
NaN != NaN true
false == 0 true
true == 1 true
true == 2 false
undefined == 0 false
null == 0 false
&quot;5&quot; == 5 true
</code></pre>
<ol start="2">
<li><p>全等于和不全等于【使用前，不会对待比较的两个值进行<code>强制类型转换</code>】</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(num1 === num2 ) &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">&quot;这两个值完全相等&quot;</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">if</span>(num1 !== num2 ) &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">&quot;这两个值不完全相等&quot;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>全等、不全等比较不仅仅比较<code>数值</code>,还比较<code>类型</code>。所以<strong>推荐使用全等、不全等</strong></p>
</blockquote>
</li>
</ol>
<h4 id="3-5-9-条件操作符"><a href="#3-5-9-条件操作符" class="headerlink" title="3.5.9 条件操作符"></a>3.5.9 条件操作符</h4><blockquote>
<p>使用 <code>boolean_expression ? true_value : false_value</code></p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> max = num1 &gt; num2 ? num1 : num2;</span><br></pre></td></tr></table></figure>

<h4 id="3-5-10-赋值操作符"><a href="#3-5-10-赋值操作符" class="headerlink" title="3.5.10 赋值操作符"></a>3.5.10 赋值操作符</h4><blockquote>
<p>用<code>=</code>，将右边的值，赋值给左边</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num = <span class="number">2</span> + <span class="number">3</span>;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>复合赋值操作符：+=、-=等等【只是简写，并没有提高性能的作用】</p>
</blockquote>
<h4 id="3-5-11-逗号操作符"><a href="#3-5-11-逗号操作符" class="headerlink" title="3.5.11 逗号操作符"></a>3.5.11 逗号操作符</h4><blockquote>
<p>可以在一条语句中，执行多个操作。</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = <span class="number">1</span> , num2 = <span class="number">2</span> , num3 = <span class="number">3</span>;</span><br></pre></td></tr></table></figure>

<h3 id="3-6-语句"><a href="#3-6-语句" class="headerlink" title="3.6 语句"></a>3.6 语句</h3><h4 id="3-6-1-if"><a href="#3-6-1-if" class="headerlink" title="3.6.1 if"></a>3.6.1 if</h4><blockquote>
<p>语法：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(condiion) &#123;</span><br><span class="line">  <span class="comment">// statement1</span></span><br><span class="line">&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">  <span class="comment">// statement2</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="3-6-2-do-while"><a href="#3-6-2-do-while" class="headerlink" title="3.6.2 do-while"></a>3.6.2 do-while</h4><blockquote>
<p>语法：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">do</span>&#123;</span><br><span class="line">  <span class="comment">// statement</span></span><br><span class="line">&#125; <span class="keyword">while</span> (expression)</span><br></pre></td></tr></table></figure>
<blockquote>
<p>特点：循环体里面的函数，至少会执行一次。【<code>先执行、后判断</code>】</p>
</blockquote>
<h4 id="3-6-3-while"><a href="#3-6-3-while" class="headerlink" title="3.6.3 while"></a>3.6.3 while</h4><blockquote>
<p>语法：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">while</span>(expression)&#123;</span><br><span class="line">  <span class="comment">// statement</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="3-6-4-for"><a href="#3-6-4-for" class="headerlink" title="3.6.4 for"></a>3.6.4 for</h4><blockquote>
<p>语法：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(initalization ; expression ; post-loop-expression) &#123;</span><br><span class="line">  <span class="comment">// statement</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="3-6-5-for-in"><a href="#3-6-5-for-in" class="headerlink" title="3.6.5 for-in"></a>3.6.5 for-in</h4><blockquote>
<p>语法：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(property <span class="keyword">in</span> expression) &#123;</span><br><span class="line">  <span class="comment">// statement</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>特点：用于<code>枚举对象的非符号键属性</code></p>
</blockquote>
<h4 id="3-6-6-for-of"><a href="#3-6-6-for-of" class="headerlink" title="3.6.6 for-of"></a>3.6.6 for-of</h4><blockquote>
<p>语法：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(property <span class="keyword">of</span> expression)&#123;</span><br><span class="line">  <span class="comment">// statement</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>特点：用于<code>遍历可迭代对象的元素</code></p>
</blockquote>
<h4 id="3-6-7-标签语句"><a href="#3-6-7-标签语句" class="headerlink" title="3.6.7 标签语句"></a>3.6.7 标签语句</h4><blockquote>
<p>语法：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">label:statement</span><br></pre></td></tr></table></figure>
<blockquote>
<p>例子：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">start:<span class="keyword">for</span>(<span class="keyword">let</span> i=<span class="number">0</span> ; i&lt;<span class="number">5</span> ; i++)&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(i);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>特点：可以与break、continue结合使用，返回代码中的<code>特定位置</code>,达到<code>嵌套循环</code>的效果。</p>
</blockquote>
<h4 id="3-6-8-break-和-continue"><a href="#3-6-8-break-和-continue" class="headerlink" title="3.6.8 break 和 continue"></a>3.6.8 break 和 continue</h4><blockquote>
<p>语法：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 结合标签语句使用：</span></span><br><span class="line"><span class="keyword">let</span> num = <span class="number">0</span>;</span><br><span class="line">outermost:</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">let</span> i=<span class="number">0</span> ; i&lt;<span class="number">10</span> ; i++)&#123;</span><br><span class="line">  <span class="keyword">for</span>(<span class="keyword">let</span> j=<span class="number">0</span> ; j&lt;<span class="number">10</span> ; j++)&#123;</span><br><span class="line">    <span class="keyword">if</span>( i == <span class="number">5</span> &amp;&amp; j == <span class="number">5</span>)&#123;</span><br><span class="line">      <span class="keyword">break</span> outermost;</span><br><span class="line">    &#125;</span><br><span class="line">    num++;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(num); <span class="comment">// 55;</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>一般不建议使用其来实现循环嵌套，不然容易出错。</p>
</blockquote>
<h4 id="3-6-9-with"><a href="#3-6-9-with" class="headerlink" title="3.6.9 with"></a>3.6.9 with</h4><blockquote>
<p>作用：将代码的<code>作用域</code>设置为<code>特定的对象</code>.</p>
</blockquote>
<blockquote>
<p>语法：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="title">with</span>(<span class="params">expression</span>)</span>&#123;</span><br><span class="line">  statement;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>例子：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="title">with</span>(<span class="params">location</span>)</span>&#123;</span><br><span class="line">  <span class="keyword">let</span> qs = search.substring(<span class="number">1</span>); <span class="comment">// 等同于 location.search.substring(1);</span></span><br><span class="line">  <span class="keyword">let</span> hostName = hostname;</span><br><span class="line">  <span class="keyword">let</span> url = href;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>注意：严格模式下，不能使用with，会抛出错误。</p>
</blockquote>
<h4 id="3-6-10-switch"><a href="#3-6-10-switch" class="headerlink" title="3.6.10 switch"></a>3.6.10 switch</h4><blockquote>
<p>语法1：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">switch</span>(expression) &#123;</span><br><span class="line">  <span class="keyword">case</span> value1:</span><br><span class="line">    <span class="comment">//statement1;</span></span><br><span class="line">    <span class="keyword">break</span>;</span><br><span class="line">  <span class="keyword">case</span> value2:</span><br><span class="line">    <span class="comment">//statement2</span></span><br><span class="line">    <span class="keyword">break</span>;</span><br><span class="line">  <span class="keyword">default</span>:</span><br><span class="line">    statement3</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>语法2：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">switch</span>(<span class="literal">true</span>) &#123;</span><br><span class="line">  <span class="keyword">case</span> expression1:</span><br><span class="line">    <span class="comment">//statement1;</span></span><br><span class="line">    <span class="keyword">break</span>;</span><br><span class="line">  <span class="keyword">case</span> expression2:</span><br><span class="line">    <span class="comment">//statement2</span></span><br><span class="line">    <span class="keyword">break</span>;</span><br><span class="line">  <span class="keyword">default</span>:</span><br><span class="line">    statement3</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="3-7-函数"><a href="#3-7-函数" class="headerlink" title="3.7 函数"></a>3.7 函数</h3><blockquote>
<p>在后面<code>第十章</code>会详细介绍</p>
</blockquote>
<blockquote>
<p>语法：</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 定义</span></span><br><span class="line">  <span class="function"><span class="keyword">function</span> <span class="title">functionName</span>(<span class="params">arg0,arg1,...,argN</span>)</span>&#123;</span><br><span class="line">    <span class="comment">// statements</span></span><br><span class="line">  &#125;</span><br><span class="line"><span class="comment">// 调用</span></span><br><span class="line">  functionName(value1,...,valueN);</span><br></pre></td></tr></table></figure>
<h3 id="3-8-总结"><a href="#3-8-总结" class="headerlink" title="3.8 总结"></a>3.8 总结</h3><ol>
<li><p>ECMAScript的<code>基本数据类型</code>:Undefined、Null、Boolean、Number、String和Symbol</p>
</li>
<li><p>其中Number包括整数和浮点数</p>
</li>
<li><p>对于一些操作符而言，当遇到<code>不同类型数据</code>的时候，会自动进行<code>类型转换</code>后在进行操作。</p>
</li>
</ol>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>Copyright： </strong>
          
          Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2022/02/11/JavaScript%E5%AD%A6%E4%B9%A0/%E3%80%8AJavaScript%E9%AB%98%E7%BA%A7%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E3%80%8B-%20%E7%AC%AC%E4%B8%89%E7%AB%A0%EF%BC%9A%E8%AF%AD%E8%A8%80%E5%9F%BA%E7%A1%80/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/JavaScript/" rel="tag">JavaScript</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2022/02/12/JavaScript%E5%AD%A6%E4%B9%A0/%E3%80%8AJavaScript%E9%AB%98%E7%BA%A7%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E3%80%8B-%20%E7%AC%AC%E5%9B%9B%E7%AB%A0%EF%BC%9A%E5%8F%98%E9%87%8F%E3%80%81%E4%BD%9C%E7%94%A8%E5%9F%9F%E4%B8%8E%E5%86%85%E5%AD%98/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            《JavaScript高级程序设计》- 第四章：变量、作用域与内存
          
        </div>
      </a>
    
    
      <a href="/2022/02/09/JavaScript%E5%AD%A6%E4%B9%A0/%E3%80%8AJavaScript%E9%AB%98%E7%BA%A7%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1%E3%80%8B-%20%E7%AC%AC%E4%BA%8C%E7%AB%A0%EF%BC%9AHTML%E4%B8%AD%E7%9A%84JavaScript/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">《JavaScript高级程序设计》- 第二章：HTML中的JavaScript</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "jeb2pvxjdeJQOj5OG3AUavGv-gzGzoHsz",
    app_key: "6YlB9tQJTstHMM8GOwFu4uyY",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
   
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2022
        <i class="ri-heart-fill heart_icon"></i> 子与子乘
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></span>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
      </li>
    </ul>
  </div>
</footer>    
    </main>
    <div class="float_btns">
      <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

    </div>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="欢迎"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i></p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/js/jquery-3.6.0.min.js"></script>
 
<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->
 
<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: ".tocbot",
    contentSelector: ".article-entry",
    headingSelector: "h1, h2, h3, h4, h5, h6",
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: "main",
    positionFixedSelector: ".tocbot",
    positionFixedClass: "is-position-fixed",
    fixedSidebarOffset: "auto",
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css"
/>
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->
 <!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script> 
<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->
 
<script src="/js/busuanzi-2.3.pure.min.js"></script>
 
<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->
 
<link rel="stylesheet" href="/css/clipboard.css">
 <script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>
 
<!-- CanvasBackground -->

<script>
  if (window.mermaid) {
    mermaid.initialize({ theme: "forest" });
  }
</script>


    
    

  </div>
</body>

</html>